<?php
	define ("NEWLINE","\n");
	set_error_handler('errorHandler');

	function errorHandler ($errno, $errstr, $errfile, $errline, $errcontext)
	{
		global $cli;
		global $curCon;

		switch ($errno)
   		{
			case E_USER_WARNING:
			case E_USER_NOTICE:
	      		case E_WARNING:
		      	case E_NOTICE:
			case E_CORE_WARNING:
			case E_COMPILE_WARNING:
	         	break;

			case E_USER_ERROR:
		      	case E_ERROR:
		      	case E_PARSE:
	      		case E_CORE_ERROR:
	      		case E_COMPILE_ERROR:
		        global $query;
   
			/*	INCLUDE EXTRA INFO
	        	if (eregi('^(sql)$', $errstr))
			{
        		    $MYSQL_ERRNO = mysql_errno();
	        	    $MYSQL_ERROR = mysql_error();
	        	    $errstr = "MySQL error: $MYSQL_ERRNO : $MYSQL_ERROR";
		        }
			else 
			{
        			$query = NULL;
	        	} // if
			*/
			
			$error['date']		=	date('Y-m-d H:i:s');
			$error['name'] 		=	"$errstr (# $errno)";
//			$error['query']		= 	(empty($query)) ? '' : 'query: $query';
			$error['line'] 		=	"Error in line $errline of file '$errfile'.";
			$error['script']	= 	"Script: '{$_SERVER['PHP_SELF']}'";

			if (isset($errcontext['this']))
			{
        			if (is_object($errcontext['this']))
				{
		               		$classname 	= get_class($errcontext['this']);
        		       		$parentclass 	= get_parent_class($errcontext['this']);
		               		$error['class'] = "Object/Class: '$classname', Parent Class: '$parentclass'.\n";
        		  	} 
	        	}
			
			$string = 'Fatal error ' . $error['name'] . ' occured on ' . $error['date'] . NEWLINE . $error['line'] . NEWLINE . $error['script']. NEWLINE;
			echo $string;
//		        error_log($errorstring, 1, $_SERVER['SERVER_ADMIN']);	//email
			//make this HTML like
			$logfile = './logs/errorlog.html';
			error_log($text = $string, 3, $logfile);
			default:
	         	break;
   		} // switch
	} // errorHandler
?>
